package cn.jflow.boot.controller;

import bp.ccfast.third.goview.*;
import bp.da.*;
import bp.difference.ContextHolderUtils;
import bp.difference.SystemConfig;
import bp.difference.handler.HttpHandlerBase;
import bp.en.Entities;
import bp.en.QueryObject;
import bp.en.TSEntitiesNoName;
import bp.sys.*;
import bp.tools.Json;
import bp.tools.StringUtils;
import bp.web.WebUser;
import bp.wf.*;
import bp.wf.dts.ccbpmServices;
import bp.wf.httphandler.WF;
import bp.wf.httphandler.WF_CCForm;
import bp.wf.httphandler.WF_WorkOpt_OneWork;
import bp.wf.template.*;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@RestController
@Api(tags="工具包接口")
@RequestMapping(value = "/WF/BigAPI")
public class BigScreenAPI extends HttpHandlerBase {
    public static Object Return_Info(int code, String msg, Object data)
    {
        Hashtable ht = new Hashtable();
        ht.put("code", code);
        ht.put("message", msg);
        ht.put("msg", msg);
        ht.put("data", data);
        return ht;
    }

    /**
     * 蓝色大屏-登陆
     * @param user 用户vo
     * @param token
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "蓝色大屏-登陆", notes = "蓝色大屏-登陆")
    @PostMapping("/Port_LoginByPassword")
    public bp.tools.AjaxResult Port_LoginByPassword(@RequestBody SysUser user,String token, HttpServletRequest request) throws Exception {
        bp.tools.AjaxResult json = new bp.tools.AjaxResult();
        try{

            if (token != null) {
                Dev2Interface.Port_LoginByToken(token);
            }

            bp.port.Emp emp= new bp.port.Emp();
            emp.setNo(user.getUsername()) ;
            if ( emp.RetrieveFromDBSources()==0) {
                json.put("code", 500);
                json.put("msg","用户名或者密码错误");
                return json;
            }

            if (emp.CheckPass(user.getPassword()) == false) {
                json.put("code", 500);
                json.put("msg","用户名或者密码错误");
                return json;
            }

            //先登录再获取Token.
            Dev2Interface.Port_Login(emp.getUserID());
            token = Dev2Interface.Port_GenerToken();

            user.setUsername(WebUser.getName());
            user.setNickname(WebUser.getName());
            user.setPassword(null);
            user.setId(WebUser.getNo());

            Map<String, Object> map = new HashMap<String, Object>();
            map.put("userinfo", user);
        	Token token2 = new Token();
        	token2.setTokenName("satoken");
        	token2.setTokenValue(token);
            map.put("token", token2);

            json.put("code", 200);
            json.put("data", map);
            json.put("msg","登录成功！");
            return json;
        }catch(Exception e){
            json.put("code", 500);
            json.put("msg","登录有错误！");
            return json;
        }
    }
    /**
     * 蓝色大屏-退出登录
    */
    @RequestMapping(value = "/Port_LoginOut")
    @ApiOperation("退出登录:清除当前的会话,注销cookies.")
    public final Object Portal_LoginOut() throws Exception {
        try{
            Dev2Interface.Port_SigOut();
            return Return_Info(200,"退出成功","退出成功");
        }catch(Exception e){
            return Return_Info(500,"退出成功失败",e.getMessage());
        }
    }


    /**
     * 蓝色大屏-获取oss地址
          */
	@ApiOperation(value = "蓝色大屏-获取oss地址", notes = "蓝色大屏-获取oss地址")
	@GetMapping("/getOssInfo")
	public Object getOssInfo() {
		HttpServletRequest request = ContextHolderUtils.getRequest();
		String fullUrl = request.getRequestURL().toString();
		String prefix = fullUrl.substring(0, fullUrl.indexOf("/", 8));

		 prefix = prefix+"/DataUser/";
	     return  Return_Info(200,"获取成功",prefix);

	}
    @GetMapping(value = "/Search_EmpByToken")
    @ApiOperation("根据token查询人员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Token", value = "Token", paramType = "query", required = true,dataType = "string"),
    })
    public Object Search_EmpByToken(String Token) throws Exception {
        bp.port.Token tk = new bp.port.Token();
        tk.setMyPK(Token);
        if (tk.RetrieveFromDBSources() == 0)
        {
            throw new RuntimeException("err@ token 过期或失效.");
        }
        DataTable dt = tk.ToDataTableField();
        return Return_Info(200,"根据Token获取人员信息成功", Json.ToJson(dt));
    }
    /**
     *蓝色大屏- 获取项目列表
     */
    @GetMapping(value = "/projectList")
    @ApiImplicitParams({
        @ApiImplicitParam(name="token",value="token",required = true,dataType = "string"),
    })
    @ApiOperation("蓝色大屏-项目列表")
	public Object projectList(String token){

		if (token != null) {
            Dev2Interface.Port_LoginByToken(token);
		}
		//String userName = WebUser.getName();
		String userName  = WebUser.getUserID();

		String execSql = "select mypk as id , ProjectName as projectName,CreateTime as createTime,"
				+ "CreateUserId as createUserId,State as state,isDelete,indexImage,Remarks from goview_projects t "
				+ " where 1=1 and createUserId = '"+userName+"'  and isTemplate=-1 ";
		DataTable dt = DBAccess.RunSQLReturnTable(execSql);
		int count = dt.Rows.size();


        Hashtable ht = new Hashtable();
        ht.put("code", 200);
        ht.put("message", "获取成功");
        ht.put("data", Json.ToJson(dt));
        ht.put("count", count);
        return ht;
	}
    /**
     * 蓝色大屏-获取项目模板列表
     */
    @GetMapping(value = "/projectTemplateListApi")
    @ApiImplicitParams({
        @ApiImplicitParam(name="token",value="token",required = true,dataType = "string"),
    })
    @ApiOperation("蓝色大屏-模板列表")
	public Object projectTemplateListApi(String token){

		if (token != null) {
            Dev2Interface.Port_LoginByToken(token);
		}
		String userName = WebUser.getUserID();

		String execSql = "select mypk as id , ProjectName as projectName,CreateTime as createTime,"
				+ "CreateUserId as createUserId,State as state,isDelete,indexImage,Remarks from goview_projects t "
				+ " where 1=1 and createUserId = '"+userName+"' and isTemplate=1 ";
		DataTable dt = DBAccess.RunSQLReturnTable(execSql);
		int count = dt.Rows.size();


        Hashtable ht = new Hashtable();
        ht.put("code", 200);
        ht.put("message", "获取成功");
        ht.put("data", Json.ToJson(dt));
        ht.put("count", count);
        return ht;
	}

	/**
     * 蓝色大屏-新增保存项目信息
     * @param
     * @return
     */
	@ApiOperation(value = "蓝色大屏-新增保存项目", notes = "蓝色大屏-新增保存项目")
	@PostMapping("/create")
	public Object create( @RequestBody GoviewProjectVo goviewProjectVo ){
		GoviewProject goviewProject = new GoviewProject();
		goviewProject.setProjectname(goviewProjectVo.getProjectName());
		goviewProject.setMyPK(goviewProjectVo.getProjectName());
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
		goviewProject.setCreatetime(dateString);
		goviewProject.setCreateuserid(goviewProjectVo.getCreateUserId());
		goviewProject.setState(-1);
		goviewProject.setIsTemplate(-1);

		try {
			int b = goviewProject.Insert();
			if(b>0){
				goviewProjectVo.setState(-1);
				goviewProjectVo.setCreateTime(dateString);
                return Return_Info(200,"创建成功",goviewProjectVo);
			}else{
			     return Return_Info(500,"创建失败","");
			}
		} catch (Exception e) {
			e.printStackTrace();
		     return  Return_Info(500,"创建失败","");
		}


	}
	/**
     * 蓝色大屏-通过模板创建项目
     * @param
     * @return
     */
	@ApiOperation(value = "蓝色大屏-通过模板创建项目", notes = "蓝色大屏-通过模板创建项目")

	@PostMapping("/createByTemplate")
	public Object createByTemplate( @RequestBody GoviewProjectVo goviewProjectVo ){
		GoviewProject goviewProject = new GoviewProject();
		goviewProject.setProjectname(goviewProjectVo.getProjectName());
		goviewProject.setMyPK(goviewProjectVo.getProjectName());
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
		goviewProject.setCreatetime(dateString);
		goviewProject.setCreateuserid(goviewProjectVo.getCreateUserId());
		goviewProject.setState(-1);
		goviewProject.setIsTemplate(-1);

		try {
			int b = goviewProject.Insert();
			if(b>0){
				goviewProjectVo.setState(-1);
				goviewProjectVo.setCreateTime(dateString);

				//GoviewProjectData goviewProjectData= new GoviewProjectData();
				String execSql = "select mypk as id , projectid ,Content from goview_projectdatas where projectid = '"+goviewProjectVo.getTemplateID()+"'";
				DataTable dt = DBAccess.RunSQLReturnTable(execSql);
				int count = dt.Rows.size();
				GoviewProjectData goviewProjectData = new GoviewProjectData();
				if(count>0) {
					//String content = (String) dt.getValue(0, "Content");
					//goviewProjectData.
					String ids = (String) dt.getValue(0, "id");
					String content = (String) dt.getValue(0, "Content");

					 goviewProjectData.setCreateTime(dateString);
					 goviewProjectData.setProjectId(goviewProjectVo.getProjectName());
					 goviewProjectData.setContent(content);

					goviewProjectData.SaveBigTxtToDB("Content", content);
					goviewProjectData.Save();
					//goviewProjectData.Update();
				}else {
					 goviewProjectData.setProjectId(goviewProjectVo.getProjectName());
					 //goviewProjectData.setContent(content);
					 goviewProjectData.setCreateTime(dateString);
					 goviewProjectData.Save();
				}


                return Return_Info(200,"创建成功",goviewProjectVo);
			}else{
			     return Return_Info(500,"创建失败","");
			}
		} catch (Exception e) {
			e.printStackTrace();
		     return  Return_Info(500,"创建失败","");
		}


	}


	/**
	 * 蓝色大屏-项目表删除
	 * @param ids
	 * @return
	 */
	@ApiOperation(value = "蓝色大屏-项目表删除", notes = "蓝色大屏-项目表删除")
	@DeleteMapping("/delete")
	public Object delete(String ids){
		try {
			GoviewProject goviewProject = new GoviewProject(ids);
			//goviewProject.setMyPK(ids);
			int t = goviewProject.Delete();
		} catch (Exception e) {
			e.printStackTrace();
		     return  Return_Info(500,"删除失败","");
		 }
	     return Return_Info(200,"删除成功","");
	 }


	@ApiOperation(value = "蓝色大屏-修改项目", notes = "蓝色大屏-修改项目")
    @PostMapping("/edit")
    public Object edit(@RequestBody GoviewProjectVo goviewProjectVo)
    {

		try {
			//goviewProject.Save();
			GoviewProject goviewProject = new GoviewProject(goviewProjectVo.getId());
			//goviewProject.setMyPK(goviewProjectVo.getId());

			if(goviewProjectVo.getProjectName()!=null) {
				goviewProject.setProjectname(goviewProjectVo.getProjectName());
			}
			if(goviewProjectVo.getIndexImage()!=null) {
				goviewProject.setIndeximage(goviewProjectVo.getIndexImage());
			}

			//goviewProject.
			goviewProject.Update();
		} catch (Exception e) {
			e.printStackTrace();
		}
	     return Return_Info(200,"获取成功","");

    }


	@ApiOperation(value = "蓝色大屏-项目重命名", notes = "蓝色大屏-项目重命名")
    @PostMapping("/rename")
    @ResponseBody
    public Object rename(@RequestBody GoviewProjectVo goviewProjectVo)
    {

		GoviewProject goviewProject = new GoviewProject();
		goviewProject.setMyPK(goviewProjectVo.getId());
		goviewProject.setProjectname(goviewProjectVo.getProjectName());
		try {
			//goviewProject.Save();
			goviewProject.Update();
		} catch (Exception e) {
			e.printStackTrace();
	       return Return_Info(500,"重命名失败","");
		}
       return Return_Info(200,"重命名成功","");
    }
//

	//发布/取消项目状态
    @PutMapping("/publish")
    @ApiOperation(value = "蓝色大屏-发布项目", notes = "蓝色大屏-发布项目")
	@ResponseBody
    public Object publish(@RequestBody GoviewProjectVo goviewProjectVo) {
    	if(goviewProjectVo.getState()==-1||goviewProjectVo.getState()==1) {
    		try {
        		GoviewProject goviewProject = new GoviewProject(goviewProjectVo.getId());
        		goviewProject.setMyPK(goviewProjectVo.getId());
        		goviewProject.setState(goviewProjectVo.getState());
        		goviewProject.Update();
    		} catch (Exception e) {
    			e.printStackTrace();
    		    return Return_Info(500,"发布失败","");
    		}
    	}
	      return Return_Info(200,"发布成功","");
	}
	//设置模板
    @PutMapping("/setTemplate")
    @ApiOperation(value = "蓝色大屏-设置项目为模板", notes = "蓝色大屏-设置项目为模板")
	@ResponseBody
    public Object setTemplate(@RequestBody GoviewProjectVo goviewProjectVo) {
    	if(goviewProjectVo.getIsTemplate()==-1||goviewProjectVo.getIsTemplate()==1) {
    		try {
        		GoviewProject goviewProject = new GoviewProject(goviewProjectVo.getId());
        		goviewProject.setMyPK(goviewProjectVo.getId());
        		goviewProject.setIsTemplate(goviewProjectVo.getIsTemplate());
        		goviewProject.Update();
    		} catch (Exception e) {
    			e.printStackTrace();
    		    return Return_Info(500,"设置失败","");
    		}
    	}
	      return Return_Info(200,"设置模板成功","");
	}



    @ApiOperation(value = "蓝色大屏-获取项目数据", notes = "蓝色大屏-获取项目数据")
    @ApiImplicitParams({
        @ApiImplicitParam(name="projectId",value="项目ID",required = true,dataType = "string"),
    })
	@GetMapping("/getData")
    public Object getData(String projectId)
    {

    	GoviewProjectVo goviewProjectVo=new GoviewProjectVo();


		try {
			GoviewProject goviewProject = new GoviewProject(projectId);
	    	goviewProjectVo.setId(projectId);
	    	goviewProjectVo.setProjectName(goviewProject.getProjectname());
	    	goviewProjectVo.setIndexImage(goviewProject.getIndeximage());
	    	goviewProjectVo.setRemarks(goviewProject.getRemarks());
	    	goviewProjectVo.setState(goviewProject.getState());

            Paras pens = new Paras();
            pens.SQL="select mypk as id , projectid ,Content from goview_projectdatas where projectid = "+SystemConfig.getAppCenterDBVarStr() + "v";
            pens.Add("v",projectId);
            DataTable dt = DBAccess.RunSQLReturnTable(pens);
			int count = dt.Rows.size();
			if(count>0) {
				String content = (String) dt.getValue(0, "Content");
		    	goviewProjectVo.setContent(content);
		    	return Return_Info(200,"获取成功",goviewProjectVo);
			}else {
				return Return_Info(200,"无数据","null");
			}

		} catch (Exception e) {
	        return Return_Info(500,"无数据","");
		}


       // return Return_Info(200,"获取成功",bp.tools.Json.ToJson(goviewProjectVo));

    }


	@ApiOperation(value = "蓝色大屏-保存设计信息", notes = "蓝色大屏-保存设计信息")
	@PostMapping("/saveData")
	public Object saveData(@RequestBody GoviewProjectDataVo data) {
		bp.tools.AjaxResult json = new bp.tools.AjaxResult();
		GoviewProjectData goviewProjectData = new GoviewProjectData();

		try {
			GoviewProject goviewProject = new GoviewProject(data.getProjectId());
			if(goviewProject==null) {
		        return Return_Info(500,"没有项目信息","");
		     }
			//GoviewProjectData goviewProjectData= new GoviewProjectData();
			String execSql = "select mypk as id , projectid ,Content from goview_projectdatas where projectid = '"+data.getProjectId()+"'";
			DataTable dt = DBAccess.RunSQLReturnTable(execSql);
			int count = dt.Rows.size();

			if(count>0) {
				//String content = (String) dt.getValue(0, "Content");
				//goviewProjectData.
				String ids = (String) dt.getValue(0, "id");
				String projectid = (String) dt.getValue(0, "projectid");
				 Date currentTime = new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			        String dateString = formatter.format(currentTime);
					 goviewProjectData.setCreateTime(dateString);
				 goviewProjectData.setMyPK(ids);
				 goviewProjectData.setProjectId(projectid);
				goviewProjectData.setContent(data.getContent());

				goviewProjectData.SaveBigTxtToDB("Content", data.getContent());
				goviewProjectData.Save();
				//goviewProjectData.Update();
			}else {
				goviewProjectData.setProjectId(data.getProjectId());
				goviewProjectData.setContent(data.getContent());
				 Date currentTime = new Date();
		        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		        String dateString = formatter.format(currentTime);
				 goviewProjectData.setCreateTime(dateString);
				goviewProjectData.Save();
			}

		} catch (Exception e) {
			e.printStackTrace();
	        return Return_Info(500,"保存数据失败","");
	    }

        json.put("msg", "保存数据成功");
        json.put("code", 200);
        return Return_Info(200,"保存数据成功","");
	}

    /**
     * 蓝色大屏-通过Token登陆
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "蓝色大屏-通过Token登陆", notes = "蓝色大屏-通过Token登陆")
    @ApiImplicitParams({
        @ApiImplicitParam(name="token",value="token",required = true),
    })
	@GetMapping("/loginByToken")
	@ResponseBody
   // public final Object Port_LoginByPassword(String userNo, String password, String orgNo) throws Exception {
	public final Object loginByToken(String token) throws Exception {
		bp.tools.AjaxResult json = new bp.tools.AjaxResult();
		try{
			if(DataType.IsNullOrEmpty(token) == true){
			   	json.put("code", 500);
		        json.put("data", "");
		        json.put("msg","Token为空");
	            return json;
			}else {
	            Dev2Interface.Port_LoginByToken(token);
			}
        	SysUser user = new SysUser();

        	user.setUsername(WebUser.getName());
        	user.setNickname(WebUser.getName());
        	user.setPassword(null);
        	user.setId(WebUser.getNo());

        	Token token2 = new Token();
        	token2.setTokenName("satoken");
        	//token2.setIsLogin(bp.web.WebUser.);
        	token2.setTokenValue(WebUser.getToken());

			Map<String, Object> map = new HashMap<String, Object>();
			map.put("userinfo", user);
			map.put("token", token2);

            return Return_Info(200,"登录成功",map);
        }catch(Exception e){
        	 return Return_Info(500,"登录有错误！","");
        }
    }
    @ApiOperation(value = "蓝色大屏-上传文件", notes = "蓝色大屏-上传文件")
	@PostMapping("/upload")
	public Object upload(@RequestBody MultipartFile object) throws IOException{

       // HttpServletRequest request = ContextHolderUtils.getRequest();
       // String contentType = request.getContentType();

        String fileName = "";
        String basePath = SystemConfig.getPathOfDataUser();
        if (SystemConfig.isJarRun() == true)
            basePath = SystemConfig.getPhysicalPath() + "DataUser" + File.separator;
        //上传附件
        String filepath = "";

        if (object == null)
        	return Return_Info(500,"获取附件信息有误", "失败");
        filepath = "UploadFile/goview";
        File file = new File(basePath + filepath);
        if (file.exists() == false) {
            file.mkdirs();
        }
        // 获取文件名
        fileName = object.getOriginalFilename();
        if (fileName.indexOf("/") > -1) {
            fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
            fileName = fileName.replace(" ", "");
        }
        filepath = filepath + "/" + DBAccess.GenerGUID() + fileName;



        try {
            //CommonFileUtils.upload(request, "file", new File(basePath + filepath));
        	File desc = new File(basePath + filepath);
        	object.transferTo(desc);

        } catch (Exception e) {
            e.printStackTrace();
            return Return_Info(500, e.getMessage(), "失败");
        }

		//GoviewProjectData

		try {
			String fileName1 = fileName.substring(0, fileName.lastIndexOf("."));
//			GoviewProject goviewProject = new GoviewProject(projectId);
//	        String fileName1 = fileName.substring(0, fileName.lastIndexOf("."));
//	        // knowledge.SetValByKey("MyFileName", fileName1);
//	         goviewProject.setIndeximage("/DataUser/" + filepath);
//	         goviewProject.Update();

	         SysFileVo sysFileVo= new SysFileVo();
	         sysFileVo.setFileName(fileName1);
	         sysFileVo.setFileurl(filepath);
	         sysFileVo.setFileSize(String.valueOf(object.getSize()));

		     return Return_Info(200,"创建成功",sysFileVo);

		} catch (Exception e) {
			e.printStackTrace();
            return Return_Info(500,"创建失败","");
		}

	}
    /**
     * 蓝色大屏-动态数据测试1
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/test1")
    public final Object test1(String key) {
        try{
            System.out.println("test1:"+key);
            String p="";
            String rstr="默认文本";
            if(key!=null && !key.equals("")){
                System.out.println("key:"+key);
                p=key;
            }
            if(p.equals("1")){
                rstr="选项1";
            }else if(p.equals("2")){
                rstr="选项2";
            }
            return Return_Info(0,"",rstr);
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 蓝色大屏-动态数据测试2
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/test2")
    public final Object test2(String key) {
        try{
            System.out.println("test2："+key);
            String p="";
            String rstr="{\"dimensions\":[\"product\",\"data1\"],\"source\":[{\"product\":\"Sat\",\"data1\":110},{\"product\":\"Sun\",\"data1\":130},{\"product\":\"Wed\",\"data1\":150},{\"product\":\"Thu\",\"data1\":80}]}";
            if(key!=null && !key.equals("")){
                System.out.println("key:"+key);
                p=key;
            }
            if(p.equals("1")){
                rstr="{\"dimensions\":[\"product\",\"data1\"],\"source\":[{\"product\":\"Mon\",\"data1\":120},{\"product\":\"Tue\",\"data1\":200},{\"product\":\"Wed\",\"data1\":150}]}";
            }else if(p.equals("2")){
                rstr="{\"dimensions\":[\"product\",\"data1\"],\"source\":[{\"product\":\"Thu\",\"data1\":80},{\"product\":\"Fri\",\"data1\":70}]}";
            }
            return Return_Info(0,"", JSONObject.parseObject(rstr));
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 蓝色大屏-动态数据测试3
     * sql传输
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/sql")
    public final Object sql(String key,  @RequestBody String sql) {
        try{
            System.out.println("test3："+key);
            System.out.println("sql:"+sql);
            String p="";
            String rstr="sql默认文本";
            if(key!=null && !key.equals("")){
                System.out.println("key:"+key);
                p=key;
            }

            if(p.equals("1")){
                rstr="sql选项1";
            }else if(p.equals("2")){
                rstr="sql选项2";
            }
            return Return_Info(0,"",rstr);
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }

	/// <summary>
	/// 获得Search的数据.
	/// </summary>
	/// <param name="token">token</param>
	/// <param name="searchID"></param>
	/// <param name="paras">参数: @key=val@key1=val1</param>
	/// <returns></returns>
	@RequestMapping(value = "/DBSrc_GenerSearchData")
	@ApiOperation("获得Search的数据")
	public Object DBSrc_GenerSearchData(String token, String searchID, String paras) {
		try
		{
			//根据token登录.
			Dev2Interface.Port_LoginByToken(token);
			SFSearch sFSearch = new SFSearch(searchID);
			String strs = sFSearch.GenerDataOfJson(paras);
			return Return_Info(200, "执行成功", strs);
		}
		catch (Exception ex)
		{
			return Return_Info(300, "失败", ex.getMessage());
		}
	}
	/// <summary>
	/// 查询列表
	/// </summary>
	/// <param name="token"></param>
	/// <param name="searchID"></param>
	/// <param name="paras"></param>
	/// <returns></returns>
	@RequestMapping(value = "/DBSrc_SearchList")
	@ApiOperation("获得Search的数据")
	public Object DBSrc_SearchList(String token)
	{
		try
		{
			//根据token登录.
			Dev2Interface.Port_LoginByToken(token);
			String sql="select s.no,s.name ,s.fk_sfdbsrc,d.name dbname from sys_sfsearch s left join Sys_SFDBSrc d on s.FK_SFDBSrc=d.no order by fk_sfdbsrc";
			DataTable dt = DBAccess.RunSQLReturnTable(sql);
			return Return_Info(200, "执行成功", Json.ToJson(dt));
		}
		catch (Exception ex)
		{
			return Return_Info(300, "失败",ex.getMessage());
		}
	}
	@Override
	public Class getCtrlType() {
		return null;
	}
}
